package com.company.cloud.company.modules.app.controller;

import com.company.cloud.common.asserts.ValidatorUtils;
import com.company.cloud.common.auth.annotation.Login;
import com.company.cloud.common.bean.BaseResult;
import com.company.cloud.common.bean.LoginSimpleUserInfo;
import com.company.cloud.common.utils.AuthContextUtils;
import com.company.cloud.company.modules.mgr.controller.req.CashConfigSaveParam;
import com.company.cloud.company.modules.api.response.CashConfigResp;
import com.company.cloud.company.modules.mgr.service.CashConfigMgrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Log4j2
@Login
@RestController
@RequestMapping("/app/user/cashConfig")
@Api(tags="CashConfig_Mgr_公司分佣基础配置")
public class CashConfigMgrController {

    @Autowired
    private CashConfigMgrService cashConfigMgrService;

    @PostMapping("/saveOrEdit")
    @ApiOperation(value="新增/修改", response= BaseResult.class)
    public BaseResult save(@RequestBody CashConfigSaveParam params) {
        ValidatorUtils.validate(params);
        LoginSimpleUserInfo userInfo = AuthContextUtils.getUser();
        cashConfigMgrService.saveOrEdit(params, userInfo.getCompanyNo(), userInfo);
        return BaseResult.ok();
    }

    @GetMapping("/get")
    @ApiOperation(value="查询", response= CashConfigResp.class)
    public BaseResult get() {
        LoginSimpleUserInfo userInfo = AuthContextUtils.getUser();
        return BaseResult.ok(cashConfigMgrService.get(userInfo.getCompanyNo()));
    }





}
